package com.my.screenadapter.mSharedPreferences;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.my.screenadapter.Base.BaseActivity;
import com.my.screenadapter.R;

import org.apache.log4j.Logger;

import butterknife.BindView;
import butterknife.ButterKnife;

public class SharedpreferenceActivity extends BaseActivity {
    Logger logger = Logger.getLogger(SharedpreferenceActivity.class);
    String sharedName = "testShare";
    @BindView(R.id.et_nums)
    EditText etNums;
    @BindView(R.id.btn_edit)
    Button btnEdit;
    @BindView(R.id.btn_clear)
    Button btnClear;
    private SharedPreferences mSp;

    @Override
    protected void init() {

    }

    @Override
    protected int initLayoutId() {
        mSp = getSharedPreferences(sharedName, Context.MODE_PRIVATE);
        return R.layout.activity_sharedpreference;
    }

    public void btnEdit(View view) {
        logger.info("btnEdit ------start -------");
        String trim = etNums.getText().toString().trim();
        if (TextUtils.isEmpty(trim)){

        }else {
            int i = Integer.parseInt(trim);
            for (int j = 0; j < i; j++) {
                SpUtil.writeSpString(mSp,"key--"+i, "value--"+i);
            }
        }
        logger.warn("btnEdit ------end -------");
    }

    public void btnClear(View view) {
        logger.info("btnClear ------start -------");
        SpUtil.clearSp(mSp);
        logger.warn("btnClear ------start -------");
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }
}
